package com.jy.oms.framework.asyn.task.checker;

import com.jy.oms.framework.asyn.task.checker.model.ExecutorCheckParam;
import com.jy.oms.framework.asyn.task.checker.model.ExecutorCheckResult;
import com.jy.oms.framework.asyn.task.collector.TaskRunningStateCollector;
import com.jy.oms.framework.asyn.task.constants.TaskStateEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 判断任务是否已经执行过
 *
 * @author liuquan
 */
@Service
public class TaskRunningChecker implements IExecutorChecker {

    @Autowired
    private TaskRunningStateCollector taskRunningStateCollector;

    @Override
    public ExecutorCheckResult canExecute(ExecutorCheckParam executorCheckParam) {
        boolean canExecute = taskRunningStateCollector.canExecute(executorCheckParam.getParamIdentifier());
        ExecutorCheckResult checkResult = new ExecutorCheckResult();
        checkResult.setResult(canExecute);
        if (!canExecute) {
            checkResult.setTaskState(TaskStateEnum.DONE);
        }
        return checkResult;
    }
}
